<script setup lang="ts">
import { computed, ref } from 'vue'
import type { Ref } from 'vue'
const loginpassword1: Ref<string> = ref('')
const loginpassword2: Ref<string> = ref('')
function onSubmit() {
    //提交的方法
}

import { useRouter } from 'vue-router';
const router = useRouter();
import { dofinishregisterFn } from '@/api/register'
import { showToast } from 'vant';
function register() {
    if (loginpassword1.value == loginpassword2.value) {
        dofinishregisterFn({ tel: localStorage.getItem('tel') || '',password: loginpassword1.value }).then(res => {
            console.log(33, res,loginpassword1.value);
            showToast(res.data.message)
            router.push('/login')
        })
    } else {
        alert("两次密码不一致！")
    }
}


const flag:Ref<boolean>=computed(()=>{
    if(loginpassword1.value.length<6){
        return true
    }else{
        return loginpassword1.value == loginpassword2.value
    }
})

// const flag: Ref<boolean> = computed(() => {  实现不了两次密码输入一致然后启用注册按钮
//     return loginpassword1.value != loginpassword2.value
// })
</script>

<template>

    <van-form @submit="onSubmit">
        <van-cell-group inset style="height: 120px;">
            <van-field v-model="loginpassword1" name="密码" label="密码" placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]">

            </van-field>
            <van-field v-model="loginpassword2" name="密码" label="密码" placeholder="确认密码"
                :rules="[{ required: true, message: '请再次填写密码' }]">

            </van-field>

        </van-cell-group>
        <div style="margin: 16px;">
            <van-button :disabled="!flag" round block color="#f66" native-type="submit" @click="register">
                注册
            </van-button>
        </div>

    </van-form>

</template>
